<?php
/**
* Change logs
* Sep 9, 2011 - trungdt - Add function: show data collected from other sermons modules
*/
class documentsmodule_config {
	function form($object) {
		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();

		$form = new form();
		if (!isset($object->item_per_page)) {
			$object->item_per_page = 50;
			$object->mp3_col = 0;$object->pdf_col = 0;
			$object->doc_col = 0;$object->ppt_col = 0;
            $object->flv_col = 0;$object->xls_col = 0;
			// Add on Sep 9, 2011 - aggregate
			$object->aggregate = array();
			$object->not_allow_post = 0;
		} else {
			$form->meta('id',$object->id);
		}
		
		// Sep 9, 2011 - begin
		$loc = unserialize($object->location_data);
		$sermons = exponent_modules_getModuleInstancesByType('documentsmodule');
		$saved_aggregates = empty($object->aggregate) ? array() : unserialize($object->aggregate);
		$all_sermons = array();
		$selected_sermons = array();
		foreach ($sermons as $src => $cal) {
			$sermons_name = (empty($cal[0]->title) ? 'Untitled' : $cal[0]->title).' on page '.$cal[0]->section;
			if ($src != $loc->src) {
				if (in_array($src, $saved_aggregates)) {
					$selected_sermons[$src] = $sermons_name;
				} else {
					$all_sermons[$src] =  $sermons_name;
				}
			}
		}
		$form->register(null,'',new htmlcontrol('<h1>Merge Documents</h1><hr size="1" />'));
		$form->register('aggregate',"Merge Document from these other Documents Module",new listbuildercontrol($selected_sermons,$all_sermons));
		$form->register("not_allow_post","Dont allow post new documents on this module instance, also, dont force use same top header sentence",new checkboxcontrol($object->not_allow_post,true));
		// Sep 9, 2011 - end
		$form->register('item_per_page',"Item per page",new textcontrol($object->item_per_page));
		$form->register('mp3_col',"MP3 Collection",new file_collection_control($object->mp3_col));
		$form->register('doc_col',"Document Collection",new file_collection_control($object->doc_col));
		$form->register('pdf_col',"PDF Collection",new file_collection_control($object->pdf_col));
		$form->register('ppt_col',"PPT Collection",new file_collection_control($object->ppt_col));
        $form->register('flv_col',"Video Collection",new file_collection_control($object->flv_col));
        $form->register('xls_col',"Excel Collection",new file_collection_control($object->xls_col));
		$form->register('submit','',new buttongroupcontrol('Save','','Cancel'));
		return $form;
	}

	function update($values,$object) {
		$object->item_per_page = $values['item_per_page'];
		$object->mp3_col=$values['mp3_col']; $object->pdf_col=$values['pdf_col'];
		$object->doc_col=$values['doc_col']; $object->ppt_col=$values['ppt_col'];
        $object->doc_col=$values['flv_col']; $object->ppt_col=$values['xls_col'];
		// Sep 9, 2011 - trungdt - Sermon Aggregate Begin
		$object->aggregate = serialize(listbuildercontrol::parseData($values,'aggregate'));
		if (isset($values['not_allow_post']))
		{
			$object->not_allow_post = 1;
		}
		else
		{
			$object->not_allow_post = 0;
		}
		// Sep 9, 2011 - trungdt - end
		return $object;
	}
}

?>
